package com.company.indicationshots.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatTextView;
//射靶分析页面按钮绘制边框
public class ShotAnalyseBorderView extends AppCompatTextView {
    private Paint topRightPaint;
    private Paint bottomLeftPaint;
    private String color1 = "#888888";
    private String color2 = "#FFFFFF";
    private String draw = "绘制";
  
    public ShotAnalyseBorderView(Context context,String draw) {
        super(context);
        this.draw = draw;
        init();  
    }

    public ShotAnalyseBorderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ShotAnalyseBorderView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public void setColor(String color1,String color2){
        this.color1 = color1;
        this.color2 = color2;
        init();
        invalidate();
    }

    private void init() {  
        topRightPaint = new Paint();  
        topRightPaint.setColor(Color.parseColor(color1)); // 设置上右边框颜色为灰色
        topRightPaint.setStyle(Paint.Style.STROKE);  
        topRightPaint.setStrokeWidth(2); // 设置边框宽度  
  
        bottomLeftPaint = new Paint();  
        bottomLeftPaint.setColor(Color.parseColor(color2)); // 设置下左边框颜色为白色
        bottomLeftPaint.setStyle(Paint.Style.STROKE);  
        bottomLeftPaint.setStrokeWidth(2); // 设置边框宽度  
    }  
  
    @Override  
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);  
  
        int width = getWidth();  
        int height = getHeight();  

        if ("绘制".equals(draw)){
            // 绘制上右边框
            canvas.drawRect(0, 0, width - 1, 2, topRightPaint); // 高度为2表示只绘制上边框
            canvas.drawRect(width - 2, 0, width, height, topRightPaint); // 宽度为2表示只绘制右边框

            // 绘制下左边框（注意这里需要减去边框宽度，以避免重叠）
            canvas.drawRect(0, height - 2, width - 2, height, bottomLeftPaint); // 高度为2表示只绘制下边框
            canvas.drawRect(0, 0, 2, height - 1, bottomLeftPaint); // 宽度为2表示只绘制左边框
        }

    }  
}